package com.smart.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smart.common.PageInfo;
import com.smart.mapper.ProjectMapper;
import com.smart.model.dtomapper.ProjectStatusAxisDtoMapper;
import com.smart.model.domain.ProjectStatusAxisDO;
import com.smart.mapper.ProjectStatusAxisMapper;
import com.smart.model.request.ProjectStatusAxisRequest;
import com.smart.service.ProjectStatusAxisService;
import com.smart.model.convert.ProjectStatusAxisConvert;
import com.smart.model.vo.ProjectStatusAxisVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author zhanghong
 */
@Service
public class ProjectStatusAxisServiceImpl extends ServiceImpl<ProjectStatusAxisMapper, ProjectStatusAxisDO> implements ProjectStatusAxisService {
    @Autowired
    private ProjectStatusAxisMapper projectStatusAxisMapper;

    @Override
    public ProjectStatusAxisVO getByKey(long id) {
        ProjectStatusAxisDO projectStatusAxisDO = getById(id);
        ProjectStatusAxisVO projectStatusAxisVO = ProjectStatusAxisDtoMapper.INSTANCE.do2VO(projectStatusAxisDO);
        return projectStatusAxisVO;
    }

    @Override
    public PageInfo<ProjectStatusAxisVO> pageQuery(ProjectStatusAxisRequest request) {
        long count = projectStatusAxisMapper.pageCount(request);
        List<ProjectStatusAxisDO> list = projectStatusAxisMapper.pageQuery(request, request.getPageSize(), request.fetchOffSet());
        List<ProjectStatusAxisVO> projectStatusAxisVOList = ProjectStatusAxisConvert.buildProjectStatusAxisVoList(list);
        return new PageInfo(request.getPageNum(), request.getPageSize(), projectStatusAxisVOList, count);
    }

    @Override
    public List<ProjectStatusAxisVO> listQuery(ProjectStatusAxisRequest request) {
        List<ProjectStatusAxisDO> list = list();
        List<ProjectStatusAxisVO> projectStatusAxisVOS = ProjectStatusAxisConvert.buildProjectStatusAxisVoList(list);
        return projectStatusAxisVOS;
    }

    @Override
    public Boolean add(ProjectStatusAxisRequest request) {
        ProjectStatusAxisDO projectStatusAxisDO = ProjectStatusAxisDtoMapper.INSTANCE.request2DO(request);
        save(projectStatusAxisDO);
        return true;
    }

    @Override
    public Boolean updateByKey(ProjectStatusAxisRequest request) {
        ProjectStatusAxisDO projectStatusAxisDO = ProjectStatusAxisDtoMapper.INSTANCE.request2DO(request);
        save(projectStatusAxisDO);
        return true;
    }

    @Override
    public Boolean deleteByKey(long id) {
        projectStatusAxisMapper.deleteDOById(id);
        return true;
    }
}
